#include "widget.h"
#include "ui_widget.h"
#include<QIcon>
#include<QPushButton>
#include"gameseleced.h"
#include<QSound>
#include<QPainter>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //设置图标
    this->setWindowIcon(QIcon(":/icon.png"));
    //设置标题
    this->setWindowTitle("贪吃蛇");
    QPushButton *button=new QPushButton(this);
    button->setText("开始游戏");
 //获取界面的大小
   this->setFixedSize(1000,800);
     QRect rect=this->geometry();
  button->move(rect.width()/2.2,rect.height()*0.7);
//设置字体
   QFont font("华文行楷",24);
    button->setFont(font);
    //设置按钮边距为0，更好看
    button->setStyleSheet("QPushButton{border:0px;}");
//设置开始游戏按钮的槽函数
   gameSeleced* gameselect =new gameSeleced;
    connect(button,&QPushButton::clicked,[=](){
       this->close();
        gameselect->setGeometry(this->geometry());
          QSound::play (":/clicked.wav");
       gameselect->show();

    });

}

Widget::~Widget()
{
    delete ui;
}
//重写绘图事件
void Widget::paintEvent(QPaintEvent *event)
{
    //实例化画家对象
    QPainter painter(this);
    //准备绘图设备
    QPixmap pixmap(":/background.jpg");
    //把图片绘制上去
    painter.drawPixmap(0,0,this->width(),this->height(),pixmap);
}



